package org.nci.platform.workflow.service.impl;

import gh.priv.general.common.vo.PageResult;
import org.nci.platform.workflow.dto.SysListenerPageQuery;
import org.nci.platform.workflow.dto.SysListenerQuery;
import org.nci.platform.workflow.entity.SysListener;
import org.nci.platform.workflow.mapper.SysListenerMapper;
import org.nci.platform.workflow.service.FlowableMapperService;
import org.nci.platform.workflow.service.ISysListenerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程监听Service业务层处理
 *
 * @author Tony
 * @date 2022-12-25
 */
@Service
public class SysListenerServiceImpl implements ISysListenerService {
    @Resource
    private FlowableMapperService flowableMapperService;

    @Override
    public PageResult<SysListener> page(SysListenerPageQuery query) {
        List<SysListener> pageList = flowableMapperService.executeQuery(SysListenerMapper.class, mapper -> mapper.page(query));
        Long count = flowableMapperService.executeQuery(SysListenerMapper.class, mapper -> mapper.pageCount(query));
        return PageResult.of(pageList, count, query.getPageSize(), query.getPageNum());
    }

    @Override
    public void export(HttpServletResponse response, SysListenerQuery query) {

    }

    @Override
    public SysListener getById(Long id) {
        return flowableMapperService.executeQuery(SysListenerMapper.class, mapper -> mapper.getById(id));
    }

    @Override
    public void save(SysListener sysListener) {
        flowableMapperService.executeUpdate(SysListenerMapper.class, mapper -> mapper.save(sysListener));
    }

    @Override
    public void updateById(SysListener sysListener) {
        flowableMapperService.executeUpdate(SysListenerMapper.class, mapper -> mapper.updateById(sysListener));
    }

    @Override
    public void removeByIds(List<Long> ids) {
        flowableMapperService.executeUpdate(SysListenerMapper.class, mapper -> mapper.removeByIds(ids));
    }
}
